<template>

    <div>

        <el-button type="primary" @click="goInfoList">招聘市场</el-button>

        <el-upload
                class="upload-demo" :show-file-list="false"
                :on-success="uploadSuccess"
                action="http://localhost:10010/zhaopinmy/user-resume/upload">
            <el-button type="warning">上传/更新我的简历</el-button>
        </el-upload>



        <div v-if="!userResume.id">
            <p>你还没有上传你的简历呢，快去上传吧</p>
        </div>

        <div v-if="userResume.id">
            <p>简历预览：</p>
            <!--fileHref为上传文件的服务器访问路径-->
            <iframe :src="'http://localhost:10010/zhaopinmy/file/'+userResume.priviewFileUrl" height="800px" width=100%></iframe>
        </div>

    </div>

</template>

<script>
    export default {
        name: "my",
        data(){
            return {
                user:{},
                userResume:{}
            }
        },
        methods:{
            uploadSuccess(res){//上传接口的返回路径
                let filename = res.data;
                this.$message.success(filename);

                //1、预览简历

                //2、存储简历信息

                let userResume = {
                    uid:this.user.id,
                    wordFileUrl:filename,
                    priviewFileUrl:filename+".pdf"
                }

                this.axios.post("/zhaopinmy/user-resume/add",userResume).then(res=>{

                    userResume.id = res.data.data;
                    this.userResume = userResume;

                })



            },


            goInfoList(){
                this.$router.push("/infoList")
            },
            initData(){
                this.axios.post("/zhaopinmy/user-resume/findResumeByUid?uid="+this.user.id).then(res=>{
                    if(res.data.data!=null){
                        this.userResume = res.data.data;
                    }
                })

            }

        },
        created(){
            let user = localStorage.getItem("zhaopin_user");
            if(!user){
                this.$message.error("请先去登录")
                setTimeout(()=>{
                    this.$router.push("/")
                },1500)
            }else{
                this.user = JSON.parse(user);
                this.initData();
            }

        }
    }
</script>

<style scoped>

</style>
